#include "initiator_top.h"

void initiator_top::thread_process(){
  tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
  sc_time delay = sc_time(10, SC_NS);

  for(int i=32; i<96; i+=4){
    tlm::tlm_command cmd = static_cast<tlm::tlm_command>(rand() % 2);
    if (cmd == tlm::TLM_WRITE_COMMAND){
      data = 0xFF000000 | i;
    }
    trans -> set_command(cmd);
    trans -> set_address(i);
    trans -> set_data_ptr(reinterpret_cast<unsigned char*>(&data)); //unsigned char只占一个字节
    trans -> set_data_length(4);
    trans -> set_streaming_width(4);
    trans -> set_byte_enable_ptr(0);
    trans -> set_dmi_allowed(false);
    trans -> set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);

    socket -> b_transport(*trans, delay);
    if(trans -> is_response_error()){
      SC_REPORT_ERROR("TLM 2.0", "Response error from b_transport");
    }
    cout << "trans = { " << (cmd ? 'W' : 'R') << ", " << hex << i
         << " } , data = " << hex << data << " at time " << sc_time_stamp()
         << " delay = " << delay << endl;
    wait(delay);
  }
}
